<template>
  <div class="deparBlank">
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="姓名">
        <el-input v-model="formInline.realname" placeholder="请输入姓名" ></el-input>
      </el-form-item>
      <el-form-item label="工号">
        <el-input v-model="formInline.workNo" placeholder="请输入工号" ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getDepartMentMessage()"
          >查询</el-button
        >
        <el-button type="primary" icon="el-icon-refresh-left" @click="reset()"
          >重置</el-button
        >
      </el-form-item>
      <el-table :data="tableData" height="250" border style="width: 100%">
        <el-table-column type="index" prop="id" label="#" width="80">
        </el-table-column>
        <el-table-column
          v-for="(item, index) in headdeta"
          :key="index"
          :prop="item.prop"
          :label="item.label"
        ></el-table-column>
      </el-table>
      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[5, 10, 20]"
      :page-size="10"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    </el-form>
  </div>
</template>
<script>
import { getredMesend } from "@/api/departManagement";
export default {
  watch:{
    tableData_1: {
      handler (newVal, oldVal) { // newVal是获取的是新的值
        this.tableData = newVal;
      },
      deep: true // deep属性是深度监听formData对象里的属性的值是否改变。
    }
  },
  mounted() {
    let _self = this;
    _self.getDepartMentMessage();
  },
  props:{
    tableData_1:{
      type:Array,
      default:()=>{
        return []
      }
    }
  },

  data() {
    return {
      tableData:[],
      pageNo: 1,
      total: 0,
      pageSize: 10,
      formInline:{
        realname:"",
        workNo: "",
      },
      headdeta: [
        {
          prop: "realname",
          label: "姓名",
        },
        {
          prop: "workNo",
          label: "工号",
        },
        {
          prop: "departName",
          label: "部门",
        },
        {
          prop: "post",
          label: "职务",
        },
        {
          prop: "telephone",
          label: "手机",
        },
        {
          prop: "email",
          label: "公司邮箱",
        },
      ],
      selectData: [],
    };
  },
  methods: {

 //重置
    reset() {
      let _self = this;
      _self.tableData = [];
      _self.formInline.realname = "";
      _self.formInline.workNo = "";
      _self.formInline.departName = "";
      _self.post = "";
      _self.telephone = "";
      _self.email = "";
      _self.pageNo = 1;
      _self.pageSize = 10;
      _self.getDepartMentMessage();
    },
    //调取列表接口
    getDepartMentMessage() {
      let _self = this;
      _self.tableData = [];
      console.log(this.$parent)
      let data = {
        pageNo: _self.pageNo,
        pageSize: _self.pageSize,
        realname: _self.formInline.realname,
        workNo: _self.formInline.workNo,
        
      };
      getredMesend(data).then((res) => {
        console.log(res.result.records);
        for (let item of res.result.records) {
          _self.tableData.push({
            realname: item.realname,
            workNo: item.workNo,
            departName: item.departName,
            post: item.post,
            telephone: item.telephone,
            email: item.email,
          });
        }
        _self.total = res.result.total;
      });
    },
//分页
     handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
      }
  },
};
</script>
<style>
.deparBlank {
  margin: 0 10px 0 10px;
}
.deparBlank .el-input {
    width: 100%;
}
</style>